package cn.com.ddapp.ddm.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.api.OKUtilAPI;
import cn.com.ddapp.ddm.bean.HomeBean;

/**
 * Created by Administrator on 2016/8/29 0029.
 */
public class ButtomAdapter extends RecyclerView.Adapter<ButtomAdapter.MyViewHolder> {
    private Context context;
    private List<HomeBean.GuessListBean> guessList;
    private LayoutInflater inflater;

    public ButtomAdapter(Context context, List<HomeBean.GuessListBean> guessList) {
        this.context = context;
        this.guessList = guessList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_guess_list, parent, false);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        Glide.with(context).load(OKUtilAPI.imgBaseUrl + guessList.get(position).getHeadImg()).into(holder.commidImag);
        holder.nameText.setText(guessList.get(position).getName());
        holder.yuanText.setText(String.valueOf(guessList.get(position).getPrice()));
        holder.xiaoliang.setText("销量：" + String.valueOf(guessList.get(position).getSales()));
        holder.pjiataxt.setText("评价：" + String.valueOf(guessList.get(position).getComments()));
    }

    @Override
    public int getItemCount() {
        return guessList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.commidImag)
        ImageView commidImag;
        @BindView(R.id.nameText)
        TextView nameText;
//        @BindView(R.id.timaiText)
//        TextView timaiText;
        @BindView(R.id.yuanText)
        TextView yuanText;
        @BindView(R.id.xiaoliang)
        TextView xiaoliang;
        @BindView(R.id.pjiataxt)
        TextView pjiataxt;

        MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
